package controllayer;
import modellayer.Product;
import modellayer.ProductContainer;
import modellayer.ProductCopy;

import java.util.ArrayList;


/**
 * The class ProductCtrl is to take input from and perform the actions requested from the
 * class SalesUI. These actions are performed on the class ProductContainer and Product in the modellayer.
 * 
 * @author Allan Eriksen, Christian Stidsborg, Andreas Rye, Casper Madsen, Stefan Bols 
 * @version 051213
 */
public class ProductCtrl
{
	private static ProductCtrl instance;
    private ProductContainer productCon;

    /**
     * This function calls ProductContainer.getInstance singleton, which creates a new ProductContainer and furthermore 
     * makes it impossible to create more than one.
     */
    private ProductCtrl()
    {
        productCon = ProductContainer.getInstance();
    }
    
    public static ProductCtrl getInstance() {
    	if (instance==null) {
    		instance = new ProductCtrl();
    	}
    	
    	return instance;
    }
    
    public boolean deleteProductFromBarcode(String barcode)
    {
    	return productCon.deleteProductFromBarcode(barcode);
    }
    
    /**
     * This functions goes into the ProductCopy class and calls the ProductCopy method.
     * It takes a @param String barcode - 
     * Returns @return ProductCopy(barcode)
     */
    public ProductCopy getProductCopy(String barcode)
    {
        return productCon.getProductCopy(barcode);
    }
    
    public double getProductPrice(String barcode)
    {
        return productCon.getProductPrice(barcode);
    }
    
    /**
     * This method finds a product from the container out from a barcode.
     * @return Null if no product mathces, otherwise the Produc object will be returned
     */
    public Product getProductFromBarcode(String barcode) {
    	return productCon.getProductFromBarcode(barcode);
    }
    
    /**
     * This method finds a product from the container out from the product number.
     * @return Null if no product mathces, otherwise the Produc object will be returned
     */
    public Product getProductFromProductNo(String productNo) {
    	return productCon.getProductFromProductNo(productNo);
    }
    
    public boolean addProduct(String barcode, double price, String productLabel, int numberOfCopies)
    {
    	productCon.addProduct(barcode, price, productLabel, numberOfCopies);
    	
    	return true;
    }
    
    public ArrayList<Product> getProductList()
    {
    	return productCon.getProductList();
    }
    
    /*
     * This function removes a product copy from the product container.
     * @param int copyNo
     *
    public void removeProductCopy(int copyNo)
    {
        productCon.removeProductCopy(copyNo);
    }
    
    /**
     * 
     *
    public void removeProductCopies(ArrayList<ProductCopy> list)
    {
        for (ProductCopy copy:list) {
            this.removeProductCopy(copy.getCopyNo());
        }
    }*/
}
